﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entity = SoTaiChinh.Library.Entity;
using Business = SoTaiChinh.Library.Business;

public partial class templates_admin_usercontrols_reply_question : System.Web.UI.UserControl
{
    Entity.HoiDap clsE_HoiDap = new SoTaiChinh.Library.Entity.HoiDap();
    Business.HoiDap clsB_HoiDap = new SoTaiChinh.Library.Business.HoiDap();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string action = Request.QueryString["action"].ToString();
            if (action == "edit")
            {                
                lbTitle.Text = "Trả lời câu hỏi";
                int info = Convert.ToInt32(Request.QueryString["info"].ToString());
                clsE_HoiDap.Id = info;
                DataTable dtHoiDap = clsB_HoiDap.SelectPrimarykey(clsE_HoiDap);
                txtHoTen.Text = dtHoiDap.Rows[0]["HoTen"].ToString();
                txtDiaChi.Text = dtHoiDap.Rows[0]["DiaChi"].ToString();
                txtEmail.Text = dtHoiDap.Rows[0]["Email"].ToString();
                txtSoDienThoai.Text = dtHoiDap.Rows[0]["SoDienThoai"].ToString();
                txtTraLoi.Value = dtHoiDap.Rows[0]["CauTraLoi"].ToString();
                txtNgayDang.Text = Convert.ToDateTime(dtHoiDap.Rows[0]["NgayHoi"].ToString()).ToString("dd/MM/yyyy");                
                txtCauHoi.Text = dtHoiDap.Rows[0]["CauHoi"].ToString();                
            }
        }

    }
    protected void btnLuu_Click(object sender, EventArgs e)
    {
        bool save = false;
        string Id = Request.QueryString["info"].ToString();
        if (txtTraLoi.Value == "")
        {
            Alert.Show("Bạn chưa trả lời câu hỏi !!!");
        }
        else
        {
            clsE_HoiDap.Id = Convert.ToInt32(Id);
            clsE_HoiDap.CauTraLoi = txtTraLoi.Value;
            save = clsB_HoiDap.Update(clsE_HoiDap);
            if (save)
            { Alert.Show("Trả lời câu hỏi hoàn thành !!!"); }
            else
            { Alert.Show("Xãy ra lỗi , kiểm tra kết nối !!!"); }
        }

    }
    protected void btnQuayLai_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/admin/listquestions.aspx");
    }
}
